<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>自动升级系统</title>
<link rel="shortcut icon" href="@{'/public/Hplus/img/logo2.png'}">
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link href="/public/layui/css/layui.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<link href="/public/Hplus/css/style.css" rel="stylesheet">

</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    	<div class="ibox float-e-margins">
	   		<div class="ibox-title" >
                <ol class="breadcrumb">
				  <li><a href="#">首页</a></li>
				  <li><a href="/list/ProjectListAction/query">项目</a></li>
				  <li class="active">${dataMap?.projectName}</li>
				</ol>
            </div>
    		<div class="ibox-content">
    			<div class="row row-lg">
    				<div class="col-sm-6">
    					<form class="form-horizontal" action="@{list.PackageListAction.updateByPackageName()}" id="packageForm">
    					<div  style="height:500px;overflow:auto">
							<table class="table table-striped table-bordered table-hover" style="height: 20px; overflow-y: auto;">
								<thead>
									<tr>
									#{if execMap?.isError == true}
										<th>包名</th>

										<th>操作</th>
									#{/if}
									#{else}
										<th style="color: red">错误信息</th>
									#{/else}
									</tr>
								</thead>
								<tbody>
								
								#{if execMap?.isError == true}
									#{list items:execMap.result, as:'n'}
									<tr>
										<td>${n}</td>
										<!-- <td><input type="checkbox" name="packageName" value="${n}"></td> -->
										<td>
											<label class="checkbox-inline">
										  		<input type="checkbox" name="packageName" value="${n}">
											</label>
										</td>
									</tr>
									#{/list}
								#{/if}
								#{else}
									#{list items:execMap.result, as:'n'}
									  <tr>
										<td style="color: red">${n}</td>
									  </tr>
									#{/list}
								#{/else}
								</tbody>
							</table>
							</div>
							<br>
							<div class="layui-progress layui-progress-big hidden" lay-showPercent="yes" lay-filter="progressfile" id="progressfile">
								<div class="layui-progress-bar" lay-percent="0%"></div>
							</div>
							<br>
							#{list items:serveripList, as:'n'}
							<button type="button" class="btn btn-primary" lay-submit lay-filter="formDemo" serverip="${n}" id="subaa">升级${n}服务器</button>
							#{/list}
							<button type="reset" class="btn btn-danger">重置</button>
						</form>
    				</div>
    				<div class="col-sm-6">
    					<div class="panel panel-info">
    					  <div class="panel-heading">项目操作</div>
						  <ul class="list-group">
						    <li class="list-group-item"><a href="/config/configAction/query?condition.projectName=${dataMap?.projectName}">配置</a></li>
						    <li class="list-group-item">删除项目</li>
						  </ul>
						</div>
    					<div class="panel panel-success">
						  <!-- Default panel contents -->
						  <div class="panel-heading">升级日志</div>
						
						  <!-- Table -->
						  <table class="table table-striped table-bordered table-hover" id="logtable">
						    <thead>
								<tr>
									<th>编码</th>

									<th>时间</th>
								</tr>
							</thead>
							<tbody id="logtbody">
								#{list pageList, as:'log'}
									#{list log, as:'ll'}
										<tr>
											<td><a href="/log/logaction/progresshtml?condition.logId=${ll.key}&condition.projectName=${dataMap?.projectName}">#${ll.key}</a></td>
											<td><a href="/log/logaction/progresshtml?condition.logId=${ll.key}&condition.projectName=${dataMap?.projectName}">${ll.value}</a></td><!-- .format('yyyy-MM-dd HH:mm') -->
										</tr>
									#{/list}
								#{/list}
							</tbody>
						  </table>
						</div>
    				</div>
    			</div>
            	
    		</div>
    	</div>
    </div>

	<!-- 你的HTML代码 -->
	<script src="@{'/public/javascripts/jquery-1.11.1.min.js'}"></script>
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script src="@{'/public/layui/lay/dest/layui.all.js'}"></script>
	<script src="@{'/public/autodeploy/verify.js'}"></script>
	<script type="text/javascript">
	  //监听提交
	  var form = layui.form();
	  var element = layui.element();
	 form.on('submit(formDemo)', function(data){
		  
		var serverip = $(this).attr('serverip');
		var aa =  checkPackName();
		 if(!aa){
			 layer.alert("请先选择升级的jar包");
			 return false;
		 }
	   var formData = new FormData(document.getElementById("packageForm"));
	   formData.append("condition.serverip", new Array(serverip));
	   formData.append("serverip", serverip);
	   formData.append("condition.projectName", '${dataMap.projectName}');
	   //文件上传请求
	   $.ajax({
	    	url:"@{list.PackageListAction.updateByPackageName()}",
	    	type:"POST",
	    	data:formData,
	    	processData: false,
	    	contentType: false,
	    	success:function(data){
	    	},
	    	error:function(xhr,status,error){
	    		layer.alert("网络错误");
	    	}
	    });
	   
	    timeInt(serverip, formData);//启动定时
	    return false;
	  });
	 
	 //请求日志列表
	 function clockLog(formData){
		 
		 formData.append("condition.page", 1);
		 formData.append("condition.rows", 5);
		 
		 $.ajax({
		    	url:"@{log.LogAction.getLogList()}",
		    	type:"POST",
		    	data:formData,
		    	processData: false,
		    	contentType: false,
		    	success:function(data){
		    		console.log(data)
		    		if(data != null){
		    		var str = "";
		    		for(var ld in data){//list<map>
		    			var ld2 = data[ld];
		    			for(var key in ld2){
		    				str += "<tr><td><a href='/log/logaction/progresshtml?condition.logId="+ key +"&condition.projectName=${dataMap?.projectName}'>"+ "#" +key + "</a></td>" + 
		    						"<td><a href='/log/logaction/progresshtml?condition.logId="+ key + "&condition.projectName=${dataMap?.projectName}'>" + ld2[key] + "</a></td></tr>";
		    			}
		    		}
		    			$("#logtbody").html(str);
		    		}
		    	},
		    	error:function(xhr,status,error){
		    		layer.alert("网络错误");
		    	}
		    });
	 }
	 
	 
	 
	 //定时请求获取进度条
	 function timeInt(serverip, formData){
		  var tt=self.setInterval(clock, 500);
		    function clock(){
		    	$.ajax({
			    	url:"@{list.PackageListAction.getUploadProgress()}",
			    	type:"POST",
			    	data:formData,
			    	processData: false,
			    	contentType: false,
			    	success:function(data){
			    		$("#progressfile").removeClass('hidden').show();
			    		element.progress('progressfile', data + "%");
			    		if(data >= 100){
			    			window.clearInterval(tt);
			    			clockLog(formData);
			    			$("#progressfile").show().delay(2000).fadeOut(function(){
			    				element.progress('progressfile', "0%");
			    			});
			    		}
			    		
			    	},
			    	error:function(xhr,status,error){
			    		layer.alert("网络错误");
			    		window.clearInterval(tt);
		    			$("#progressfile").show().delay(2000).fadeOut(function(){
		    				element.progress('progressfile', "0%");
		    			});
			    	}
			    });
		    }
	  }
	</script>
</body>
</html>